package org.eerbaar.lang.expressions;

import org.eerbaar.lang.Expression;
import org.eerbaar.lang.HasRuntime;
import org.eerbaar.lang.runtime.Executor;
import org.eerbaar.lang.runtime.Runtime;

public class IntVar implements Expression, HasRuntime {

    private Integer value = new Integer(0);

    public IntVar(int value) {
        this.value = value;
    }

    public void increment() {
        this.value++;
    }

    public Integer getValue() {
        return this.value;
    }

    public String toString() {
        return "" + value;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + value.hashCode();
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        IntVar other = (IntVar) obj;
        if (!value.equals(other.value)) {
            return false;
        }
        return true;
    }

    @Override
    public Runtime getRuntime() {

        return new Runtime() {

            @Override
            public void execute(Executor exec) {
                //
            }

            @Override
            public Object getResult() {
                return value;
            }

        };
    }

}
